package com.regulareport.web.core.config;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class TestConditional {
    public static void main(String[] args) throws InterruptedException {
        TestInnerClass testInnerClass = new TestInnerClass();
        testInnerClass.setState(3);
        TestInnerClass.Inner inner = testInnerClass.getInner();
        System.out.println(inner.getStateAAA());
        ReentrantLock reentrantLock = new ReentrantLock();
        Condition conditionA = reentrantLock.newCondition();
        Condition conditionB = reentrantLock.newCondition();
        Condition conditionC = reentrantLock.newCondition();

        Thread ta = new Thread(() -> {
            reentrantLock.lock();// 加锁
            System.out.println("加锁成功");
            try {
                conditionA.await(); //加入A的阻塞队列
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("waitA after");
        });

        Thread tb = new Thread(() -> {
            reentrantLock.lock(); //进入同步队列
            System.out.println("B加锁成功？");
            try {
                conditionB.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("waitB after");
        });

        ta.start();
        tb.start();
        tb.join();
    }
}
